package com.linewell.system.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.validator.constraints.NotEmpty;
/**
 * 部门实体类 对应数据库表：SYS_DEPARTMENT 
 */
@Entity
@Table(name = "SYS_DEPARTMENT")
@DynamicInsert(true)
@DynamicUpdate(true)
public class SysDepartment implements Serializable {

	private static final long serialVersionUID = 15578561149630441L;
	private Integer depId; //部门编号
	private String depName;//部门名称
	private String address;//部门地址
	private String phone;//部门联系方式
	private Integer depPId; // 上级级部门ID
	private Integer sort; // 排序序号
	private String desction;//部门描述
	private Double x; // 经度
	private Double y; // 纬度
	private String icon; // 徽标
	private Byte status;//状态
	private Integer createUserId;//创建者
	private java.sql.Timestamp createTime;//创建时间
	private Integer updateUserId;//修改者
	private Date updateTime;//修改时间
	private Byte depType;	//部门类型  ： 1学校 2商家 3其他

	@Id
	@Column(name = "DEP_ID", nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getDepId() {
		return depId;
	}

	public void setDepId(Integer depId) {
		this.depId = depId;
	}
	
	@NotEmpty(message="部门名称不能为空！")
	@Column(name = "DEP_NAME", nullable = false)
	public String getDepName() {
		return depName;
	}

	public void setDepName(String depName) {
		this.depName = depName;
	}

	@Column(name = "ADDRESS")
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Column(name = "PHONE")
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "DEP_PID")
	public Integer getDepPId() {
		return depPId;
	}

	public void setDepPId(Integer depPId) {
		this.depPId = depPId;
	}

	@Column(name = "SORT")
	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}

	@Column(name = "DESCTION")
	public String getDesction() {
		return desction;
	}

	public void setDesction(String desction) {
		this.desction = desction;
	}

	@Column(name = "X")
	public Double getX() {
		return x;
	}

	public void setX(Double x) {
		this.x = x;
	}

	@Column(name = "Y")
	public Double getY() {
		return y;
	}

	public void setY(Double y) {
		this.y = y;
	}

	@Column(name = "ICON")
	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}
	
	//@NotEmpty
	@Column(name = "STATUS", nullable = false, columnDefinition = "tinyint default 9")
	public Byte getStatus() {
		return status;
	}

	public void setStatus(Byte status) {
		this.status = status;
	}

	@Column(name = "CREATE_USER_ID")
	public Integer getCreateUserId() {
		return createUserId;
	}

	public void setCreateUserId(Integer createUserId) {
		this.createUserId = createUserId;
	}

	// @Temporal(TemporalType.TIMESTAMP) //指定具体时间类型
	@Column(name = "CREATE_TIME", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
	public java.sql.Timestamp getCreateTime() {
		return createTime;
	}

	public void setCreateTime(java.sql.Timestamp createTime) {
		this.createTime = createTime;
	}

	@Column(name = "UPDATE_USER_ID")
	public Integer getUpdateUserId() {
		return updateUserId;
	}

	public void setUpdateUserId(Integer updateUserId) {
		this.updateUserId = updateUserId;
	}

	@Temporal(TemporalType.TIMESTAMP) // 指定具体时间类型
	@Column(name = "UPDATE_TIME")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	
	@Column(name = "DEP_TYPE", nullable = false, columnDefinition = "tinyint default 1")
	public Byte getDepType() {
		return depType;
	}

	public void setDepType(Byte depType) {
		this.depType = depType;
	}
	
	/**
	
		DELIMITER $$

		USE `waterorder`$$
		
		DROP FUNCTION IF EXISTS `getChildDepId`$$
		
		CREATE DEFINER=`waterorder`@`%` FUNCTION `getChildDepId`(depId INT) RETURNS VARCHAR(1000) CHARSET utf8
		BEGIN
			DECLARE v_new_result VARCHAR(1000);
			IF (depId IS NOT NULL) THEN
				   SELECT GROUP_CONCAT(DEP_ID) INTO v_new_result  FROM sys_department WHERE FIND_IN_SET(DEP_PID,depId);
				   SET v_new_result = CONCAT(depId,',',v_new_result);
				   IF (v_new_result IS NULL) THEN
					SET v_new_result = ''+depId;
				   END IF;	   		   
			ELSE
				   SET v_new_result = ''+depId;
			END IF;
			
			RETURN(v_new_result);
		END$$
		
		DELIMITER ;

	 * */
	
	
}
